package com.hh.ListNodeQuestions;



/**
 * @Author hanghao
 * @Date 2023/6/28 11:28
 * @Version 1.0
 *链表中倒数第k个节点
 * easy
 */

public class No22 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode fast = head;
        ListNode slow = head;
        while(k > 0) {
            fast = fast.next;
            k--;
        }
        while(fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
